<?php

namespace App\Domain\FamilyMember\Controllers;

use AlibabaCloud\Client\Request\Request;
use App\Domain\FamilyMember\Requests\SetFamilyPost;
use App\Http\Controllers\Controller;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Domain\FamilyMember\Services\FamilyMemberService;

class FamilyMemberController extends Controller
{
    public function index()
    {
        $user = JWTAuth::parseToken()->touser();
        return $user['id'];
    }

    //成员列表
    public function list(FamilyMemberService $familyMemberService)
    {
        $houseHolder_id = $this->index();
        $data['list'] = $familyMemberService->list($houseHolder_id);
        return $this->success($data);

    }

    //添加/编辑成员
    public function updatemember(SetFamilyPost $request,FamilyMemberService $familyMemberService){
        $houseHolder_id = $this->index();
        $param = $request->validated();
        $param['houseHolder_id'] = $houseHolder_id;
        $res['id'] = $familyMemberService->updatemember($param);
        return $this->success($res);

    }
}
